﻿Option Explicit On
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq
Imports Microsoft.Reporting.WinForms
Imports Microsoft.VisualBasic.PowerPacks


Public Class clssEvaluaciones
    Public lab As System.Windows.Forms.Label
    Public tex As System.Windows.Forms.TextBox
    Public rad As System.Windows.Forms.RadioButton
    Public cob As System.Windows.Forms.ComboBox
    Public pan As System.Windows.Forms.Panel
    Public pang As System.Windows.Forms.Panel
    Public bot As System.Windows.Forms.Button
    Public che As System.Windows.Forms.CheckBox
    Public dgrigv As System.Windows.Forms.DataGridView
    Public grap As Graphics
    Public formaParent As Form
    Public arrRow As Array
    Public utiladd As Integer
    Public objJson As New Object
    Public ruta As String
    Public tipoEquipo As Integer
    Public xanposc As Integer
    Public yanposc As Integer

    Public Sub New()
        MyBase.New()
        ' medotod con el diseño de los componentes de formulario
    End Sub
    Public Sub radio(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal idOLP As String)
        'definicion de variables y constantes a utilizar
        Dim x As Integer,
            y As Integer = 0,
            localiza As Integer = 0,
            anchotemp As Integer = 0,
            contador As Integer = 0,
            altopanel As Integer = 0
        'Consulta las respuestas para la pregunta
        Dim dstRecord As New DataSet
        dstRecord.Tables.Add("vistapreguntarespuesta")
        mdlCRUD.loadRecord(dstRecord, "vistapreguntarespuesta", "vistapreguntarespuesta", "pregunta_id = '" & id & "'", "")

        'consultamos categorias
        Dim dstRecord1 As New DataSet
        dstRecord1.Tables.Add("preguntacategoria")
        mdlCRUD.loadRecord(dstRecord1, "preguntacategoria", "preguntacategoria", "pregunta_id = '" & id & "' AND categoria_id='1'", "")
        If (dstRecord1.Tables("preguntacategoria").Rows.Count > 0) Then
            'Dividimos las columnas 
            If (columna = 1) Then
                localiza = 10
            Else
                If (columna = 2) Then
                    localiza = (forma.Width / 2) + 10
                End If
            End If

            'calculamos tamaños del panel
            If (dstRecord.Tables("vistapreguntarespuesta").Rows.Count >= 3) Then
                If (Math.Round(dstRecord.Tables("vistapreguntarespuesta").Rows.Count / 3) = 1) Then
                    altopanel = 90
                Else
                    altopanel = (Math.Round(dstRecord.Tables("vistapreguntarespuesta").Rows.Count / 3) * 50)
                End If

            Else
                altopanel = 20
            End If


            'Contruccion del panel
            Me.pan = New System.Windows.Forms.Panel
            Me.pan.Location = New System.Drawing.Point(localiza, pos + 7)
            Me.pan.Size = New System.Drawing.Size(((forma.Width / 2) - 20), altopanel)
            'Me.pan.BorderStyle = BorderStyle.FixedSingle

            'Contruccion del label
            Me.lab = New System.Windows.Forms.Label
            Me.lab.Text = nombre
            Me.lab.Name = id
            If (nombre.ToString.Length > 25) Then
                'Me.lab.Size = New System.Drawing.Size(nombre.ToString.Length * 5, 20)
                Me.lab.Size = New System.Drawing.Size(250, 20)
            Else
                'Me.lab.Size = New System.Drawing.Size(nombre.ToString.Length * 6, 20)
                Me.lab.Size = New System.Drawing.Size(250, 20)
            End If
            'Me.lab.BorderStyle = BorderStyle.FixedSingle
            Me.lab.TabIndex = 0
            Me.pan.Controls.Add(lab)

            If (dstRecord.Tables("vistapreguntarespuesta").Rows.Count >= 3) Then
                Dim lista As New System.Windows.Forms.ListBox
                lista.Name = id '& "-" & arrRow(5) & "-" & arrRow(6)
                lista.DataSource = dstRecord.Tables("vistapreguntarespuesta")
                lista.DisplayMember = dstRecord.Tables("vistapreguntarespuesta").Columns(2).ToString
                lista.ValueMember = dstRecord.Tables("vistapreguntarespuesta").Columns(4).ToString
                lista.Location = New System.Drawing.Point(10, 30)
                lista.Size = New System.Drawing.Size(100, Me.pan.Size.Height - 40)
                lista.Visible = True
                Me.pan.Controls.Add(lista)
            Else
                'Contruccion del radio
                For i = 0 To dstRecord.Tables("vistapreguntarespuesta").Rows.Count - 1
                    contador += 1
                    arrRow = dstRecord.Tables("vistapreguntarespuesta").Rows(i).ItemArray.ToArray
                    Me.rad = New System.Windows.Forms.RadioButton
                    If (i = 0) Then
                        x = (Me.lab.Size.Width + 2 + (i * 20))
                    Else
                        x = anchotemp
                    End If
                    If (contador = 3) Then
                        y += 20
                        x = 10
                        contador = 0
                    End If
                    Me.rad.Checked = False
                    Me.rad.Text = arrRow(2)
                    Me.rad.Name = arrRow(4) & "-" & id & "-" & arrRow(5) & "-" & arrRow(6)
                    Me.rad.Location = New System.Drawing.Point(x, y)
                    If (arrRow(2).ToString.Length > 8) Then
                        'Me.rad.Size = New System.Drawing.Size(arrRow(2).ToString.Length * 7, 20)
                        Me.rad.Size = New System.Drawing.Size(50, 20)
                    Else
                        'Me.rad.Size = New System.Drawing.Size(arrRow(2).ToString.Length * 20, 20)
                        Me.rad.Size = New System.Drawing.Size(50, 20)
                    End If

                    Me.rad.Visible = True
                    Me.pan.Controls.Add(Me.rad)
                    anchotemp = Me.rad.Location.X + Me.rad.Size.Width
                Next i
            End If
            forma.Controls.Add(pan)
        End If
    End Sub
    Public Sub texto(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal idOLP As String)
        Dim ancho As Integer, localiza As Integer

        'consultamos categorias
        Dim dstRecord1 As New DataSet
        dstRecord1.Tables.Add("preguntacategoria")
        mdlCRUD.loadRecord(dstRecord1, "preguntacategoria", "preguntacategoria", "pregunta_id = '" & id & "' AND categoria_id='1'", "")
        If (dstRecord1.Tables("preguntacategoria").Rows.Count > 0) Then

            If (columna = 1) Then
                localiza = 10
            Else
                If (columna = 2) Then
                    localiza = (forma.Width / 2) + 10
                End If
            End If

            Me.pan = New System.Windows.Forms.Panel
            Me.pan.Location = New System.Drawing.Point(localiza, pos + 7)
            Me.pan.Size = New System.Drawing.Size(((forma.Width / 2) - 20), 20)

            Me.lab = New System.Windows.Forms.Label
            Me.lab.Text = nombre
            Me.lab.Name = id
            'Me.lab.Size = New System.Drawing.Size(nombre.Length * 10, 20)
            Me.lab.Size = New System.Drawing.Size(100, 20)
            Me.lab.TabIndex = 0
            Me.pan.Controls.Add(lab)

            Me.tex = New System.Windows.Forms.TextBox
            'ancho = nombre.ToString.Length * 10
            ancho = lab.Size.Width + 20
            Me.tex.Name = id & "-" & arrRow(5)
            Me.tex.Location = New System.Drawing.Point(ancho, 0)
            Me.tex.Size = New System.Drawing.Size(200, 20)
            Me.tex.Visible = True

            Me.pan.Controls.Add(Me.tex)
            forma.Controls.Add(pan)
        End If
    End Sub
    Public Sub seleccion(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal idOLP As String)
        Dim dstRecord As New DataSet
        Dim ancho As Integer, localiza As Integer
        dstRecord.Tables.Add("vistapreguntarespuesta")
        mdlCRUD.loadRecord(dstRecord, "vistapreguntarespuesta", "vistapreguntarespuesta", "pregunta_id = '" & id & "'", "")

        'consultamos categorias
        Dim dstRecord1 As New DataSet
        dstRecord1.Tables.Add("preguntacategoria")
        mdlCRUD.loadRecord(dstRecord1, "preguntacategoria", "preguntacategoria", "pregunta_id = '" & id & "' AND categoria_id='1'", "")
        If (dstRecord1.Tables("preguntacategoria").Rows.Count > 0) Then
            If (columna = 1) Then
                localiza = 10
            Else
                If (columna = 2) Then
                    localiza = (forma.Width / 2) + 10
                End If
            End If

            Me.pan = New System.Windows.Forms.Panel
            Me.pan.Location = New System.Drawing.Point(localiza, pos + 7)
            Me.pan.Size = New System.Drawing.Size(((forma.Width / 2) - 20), 20)

            Me.lab = New System.Windows.Forms.Label
            Me.lab.Text = nombre
            Me.lab.Name = id
            'Me.lab.Size = New System.Drawing.Size(nombre.Length * 10, 20)
            Me.lab.Size = New System.Drawing.Size(200, 20)
            Me.lab.TabIndex = 0

            Me.pan.Controls.Add(lab)
            '--------seleccion

            Me.cob = New System.Windows.Forms.ComboBox
            ancho = Me.lab.Location.X + Me.lab.Size.Width
            Me.cob.Name = id & "-" & arrRow(5) & "-" & arrRow(6)
            Me.cob.DataSource = dstRecord.Tables("vistapreguntarespuesta")
            Me.cob.DisplayMember = dstRecord.Tables("vistapreguntarespuesta").Columns(2).ToString
            Me.cob.ValueMember = dstRecord.Tables("vistapreguntarespuesta").Columns(4).ToString
            Me.cob.Location = New System.Drawing.Point(ancho, 0)
            Me.cob.Size = New System.Drawing.Size(100, 20)
            Me.cob.Visible = True
            Me.pan.Controls.Add(Me.cob)
            forma.Controls.Add(pan)
        End If
    End Sub
    Public Sub cheke(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal idOLP As String)
        'definicion de variables y constantes a utilizar
        Dim x As Integer,
            y As Integer = 0,
            localiza As Integer = 0,
            anchotemp As Integer = 0,
            contador As Integer = 0,
            altopanel As Integer = 0
        'Consulta las respuestas para la pregunta
        Dim dstRecord As New DataSet
        dstRecord.Tables.Add("vistapreguntarespuesta")
        mdlCRUD.loadRecord(dstRecord, "vistapreguntarespuesta", "vistapreguntarespuesta", "pregunta_id = '" & id & "'", "")

        'consultamos categorias
        Dim dstRecord1 As New DataSet
        dstRecord1.Tables.Add("preguntacategoria")
        mdlCRUD.loadRecord(dstRecord1, "preguntacategoria", "preguntacategoria", "pregunta_id = '" & id & "' AND categoria_id='1'", "")
        If (dstRecord1.Tables("preguntacategoria").Rows.Count > 0) Then
            'Dividimos las columnas 
            If (columna = 1) Then
                localiza = 10
            Else
                If (columna = 2) Then
                    localiza = (forma.Width / 2) + 10
                End If
            End If

            'calculamos tamaños del panel
            If (dstRecord.Tables("vistapreguntarespuesta").Rows.Count >= 3) Then
                If (Math.Round(dstRecord.Tables("vistapreguntarespuesta").Rows.Count / 3) = 1) Then
                    altopanel = 90
                Else
                    altopanel = (Math.Round(dstRecord.Tables("vistapreguntarespuesta").Rows.Count / 3) * 50)
                End If

            Else
                altopanel = 20
            End If


            'Contruccion del panel
            Me.pan = New System.Windows.Forms.Panel
            Me.pan.Location = New System.Drawing.Point(localiza, pos + 7)
            Me.pan.Size = New System.Drawing.Size(((forma.Width / 2) - 20), altopanel)
            'Me.pan.BorderStyle = BorderStyle.FixedSingle

            'Contruccion del label
            Me.lab = New System.Windows.Forms.Label
            Me.lab.Text = nombre
            Me.lab.Name = id
            If (nombre.ToString.Length > 25) Then
                'Me.lab.Size = New System.Drawing.Size(nombre.ToString.Length * 5, 20)
                Me.lab.Size = New System.Drawing.Size(100, 20)
            Else
                'Me.lab.Size = New System.Drawing.Size(nombre.ToString.Length * 6, 20)
                Me.lab.Size = New System.Drawing.Size(100, 20)
            End If
            'Me.lab.BorderStyle = BorderStyle.FixedSingle
            Me.lab.TabIndex = 0
            Me.pan.Controls.Add(lab)

            If (dstRecord.Tables("vistapreguntarespuesta").Rows.Count >= 3) Then
                Dim lista As New System.Windows.Forms.CheckedListBox
                lista.Name = id '& "-" & arrRow(5) & "-" & arrRow(6)
                lista.DataSource = dstRecord.Tables("vistapreguntarespuesta")
                lista.DisplayMember = dstRecord.Tables("vistapreguntarespuesta").Columns(2).ToString
                lista.ValueMember = dstRecord.Tables("vistapreguntarespuesta").Columns(4).ToString
                lista.Location = New System.Drawing.Point(10, 30)
                lista.Size = New System.Drawing.Size(200, Me.pan.Size.Height - 40)
                lista.Visible = True
                Me.pan.Controls.Add(lista)
            Else
                'Contruccion del check
                For i = 0 To dstRecord.Tables("vistapreguntarespuesta").Rows.Count - 1
                    contador += 1
                    arrRow = dstRecord.Tables("vistapreguntarespuesta").Rows(i).ItemArray.ToArray
                    Me.che = New System.Windows.Forms.CheckBox
                    If (i = 0) Then
                        x = (Me.lab.Size.Width + 1 + (i * 20))
                    Else
                        x = anchotemp
                    End If
                    If (contador = 3) Then
                        y += 20
                        x = 10
                        contador = 0
                    End If
                    Me.che.Checked = False
                    Me.che.Text = arrRow(2)
                    Me.che.Name = arrRow(4) & "-" & id & "-" & arrRow(5) & "-" & arrRow(6)
                    Me.che.Location = New System.Drawing.Point(x, y)
                    If (arrRow(2).ToString.Length > 8) Then
                        Me.che.Size = New System.Drawing.Size(arrRow(2).ToString.Length * 7, 20)
                    Else
                        Me.che.Size = New System.Drawing.Size(arrRow(2).ToString.Length * 10, 20)
                    End If

                    Me.che.Visible = True
                    Me.pan.Controls.Add(Me.che)
                    anchotemp = Me.che.Location.X + Me.che.Size.Width
                Next i
            End If
            forma.Controls.Add(pan)
        End If
    End Sub
    Public Sub textoArea(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal idOLP As String)
        Dim ancho As Integer, localiza As Integer
        'consultamos categorias
        Dim dstRecord1 As New DataSet
        dstRecord1.Tables.Add("preguntacategoria")
        mdlCRUD.loadRecord(dstRecord1, "preguntacategoria", "preguntacategoria", "pregunta_id = '" & id & "' AND categoria_id='1'", "")
        If (dstRecord1.Tables("preguntacategoria").Rows.Count > 0) Then
            localiza = 10
            forma.Height = 100
            Me.pan = New System.Windows.Forms.Panel
            Me.pan.Location = New System.Drawing.Point(localiza, pos + 7)
            Me.pan.Size = New System.Drawing.Size((forma.Width - 100), 50)

            Me.lab = New System.Windows.Forms.Label
            Me.lab.Text = nombre
            Me.lab.Name = id
            'Me.lab.Size = New System.Drawing.Size(nombre.Length * 10, 20)
            Me.lab.Size = New System.Drawing.Size(100, 20)
            Me.lab.TabIndex = 0
            Me.pan.Controls.Add(lab)

            Me.tex = New System.Windows.Forms.TextBox
            'ancho = nombre.ToString.Length * 10
            ancho = lab.Size.Height + 10
            Me.tex.Name = id & "-" & arrRow(5)
            Me.tex.Location = New System.Drawing.Point(0, ancho)
            Me.tex.Size = New System.Drawing.Size(Me.pan.Width - 50, 50)
            Me.tex.MaxLength = 3
            Me.tex.Visible = True

            Me.pan.Controls.Add(Me.tex)
            forma.Controls.Add(pan)
        End If
    End Sub
    Public Sub multiple(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal tipo As String, ByVal idOLP As String)
        Dim dstRecord As New DataSet
        dstRecord.Tables.Add("pregunta")
        mdlCRUD.loadRecord(dstRecord, "pregunta", "pregunta", "pregunta_padre = '" & id & "'", "")
        Dim ancho As Integer
        'consultamos categorias
        Dim dstRecord1 As New DataSet
        dstRecord1.Tables.Add("preguntacategoria")
        mdlCRUD.loadRecord(dstRecord1, "preguntacategoria", "preguntacategoria", "pregunta_id = '" & id & "' AND categoria_id='1'", "")
        If (dstRecord1.Tables("preguntacategoria").Rows.Count > 0) Then

            Me.pan = New System.Windows.Forms.Panel
            Me.pan.Location = New System.Drawing.Point(10, pos + 7)
            Me.pan.Size = New System.Drawing.Size((forma.Width - 30), 20)

            Me.lab = New System.Windows.Forms.Label
            Me.lab.Text = nombre
            Me.lab.Size = New System.Drawing.Size(250, 20)
            Me.lab.TabIndex = 0

            Me.pan.Controls.Add(lab)
            Me.pan = controlesAnidados(nombre, id, Me.pan, Me.lab.Size.Width, tipo, 0, idOLP)
            For i = 0 To dstRecord.Tables("pregunta").Rows.Count - 1
                arrRow = dstRecord.Tables("pregunta").Rows(i).ItemArray.ToArray
                Me.pan = controlesAnidados(arrRow(1), arrRow(0), Me.pan, Me.utiladd, arrRow(3), 1, idOLP)
            Next i
            forma.Controls.Add(Me.pan)
        End If
    End Sub
    Public Sub boton(ByVal ultimo As Integer, ByVal forma As Form)
        Me.bot = New System.Windows.Forms.Button
        Me.formaParent = forma
        Me.bot.Location = New System.Drawing.Point(450, ultimo + 100)
        Me.bot.Size = New System.Drawing.Size(75, 23)
        Me.bot.Text = "Aceptar"
        AddHandler bot.Click, AddressOf bot_Click
        forma.Controls.Add(Me.bot)
    End Sub
    Public Class session
        Public id As String
        Public ojb As New Collection
    End Class
    Public Class sessionR
        Public id As String
        Public ojb() As Pregunta
    End Class

    Protected Sub bot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim Ctl As Control
        Dim rad As RadioButton
        Dim cob As ComboBox
        Dim che As CheckBox
        Dim lab As Label
        Dim libx As ListBox
        Dim chelis As CheckedListBox
        Dim datgri As DataGridView
        Dim id As Array
        Dim strJson As New Collection
        Dim x As Integer
        For x = Me.formaParent.Controls.Count - 1 To 0 Step -1
            Ctl = Me.formaParent.Controls.Item(x)
            If TypeOf (Ctl) Is GroupBox Then
                Dim Control As GroupBox = Ctl
                Dim ses As New session
                ses.id = Control.Text
                For j = Control.Controls.Count - 1 To 0 Step -1
                    Ctl = Control.Controls.Item(j)
                    If TypeOf (Ctl) Is Panel Then
                        Dim pane As Panel = Ctl
                        For s = pane.Controls.Count - 1 To 0 Step -1
                            Ctl = pane.Controls.Item(s)
                            If TypeOf (Ctl) Is TextBox Or TypeOf (Ctl) Is RadioButton Or TypeOf (Ctl) Is ComboBox Or TypeOf (Ctl) Is ListBox Or TypeOf (Ctl) Is CheckedListBox Or TypeOf (Ctl) Is DataGridView Then
                                If TypeOf (Ctl) Is TextBox Then
                                    If pane.Controls.Item(s).Text <> "" Then
                                        Dim p As New Pregunta
                                        id = Split(pane.Controls.Item(s).Name, "-")
                                        p.id = id(0)
                                        p.respuesta = pane.Controls.Item(s).Text()
                                        p.respuestaOLP = pane.Controls.Item(s).Text()
                                        p.idOLP = id(1)
                                        ses.ojb.Add(p)
                                    End If
                                End If
                                If TypeOf (Ctl) Is RadioButton Then
                                    rad = pane.Controls.Item(s)
                                    If rad.Checked = True Then
                                        Dim p As New Pregunta
                                        id = Split(rad.Name, "-")
                                        p.id = id(1)
                                        p.respuesta = id(0)
                                        p.respuestaOLP = id(3)
                                        p.idOLP = id(2)
                                        ses.ojb.Add(p)
                                    End If
                                End If
                                If TypeOf (Ctl) Is ComboBox Then
                                    cob = pane.Controls.Item(s)
                                    If (cob.Name <> "Result") Then
                                        Dim p As New Pregunta
                                        id = Split(cob.Name, "-")
                                        p.id = id(0)
                                        p.respuesta = cob.SelectedValue.ToString
                                        p.respuestaOLP = id(2)
                                        p.idOLP = id(1)
                                        ses.ojb.Add(p)
                                    End If
                                End If
                                If TypeOf (Ctl) Is CheckBox Then
                                    che = pane.Controls.Item(s)
                                    If che.Checked = True Then
                                        Dim p As New Pregunta
                                        id = Split(che.Name, "-")
                                        p.id = id(1)
                                        p.respuesta = id(0)
                                        p.respuestaOLP = id(3)
                                        p.idOLP = id(2)
                                        ses.ojb.Add(p)
                                    End If
                                End If
                                If TypeOf (Ctl) Is ListBox Then
                                    libx = pane.Controls.Item(s)
                                    Dim p As New Pregunta
                                    id = Split(libx.Name, "-")
                                    p.id = id(0)
                                    p.respuesta = libx.SelectedValue.ToString
                                    p.respuestaOLP = id(2)
                                    p.idOLP = id(1)
                                    ses.ojb.Add(p)
                                End If
                                If TypeOf (Ctl) Is CheckedListBox Then
                                    chelis = pane.Controls.Item(s)
                                    For Each chel In chelis.CheckedItems
                                        Dim p As New Pregunta
                                        id = Split(chelis.Name, "-")
                                        p.id = id(0)
                                        p.respuesta = chel.Item("preguntarespuesta_valor").ToString
                                        p.respuestaOLP = id(2)
                                        p.idOLP = id(1)
                                        ses.ojb.Add(p)
                                    Next
                                End If
                                If TypeOf (Ctl) Is DataGridView Then
                                    datgri = pane.Controls.Item(s)
                                    For i = 0 To datgri.RowCount - 1
                                        Dim p1 As New Pregunta
                                        p1.id = 131
                                        p1.respuesta = datgri.Rows(i).Cells(1).Value & "-" & datgri.Rows(i).Cells(2).Value
                                        p1.respuestaOLP = ""
                                        p1.idOLP = ""
                                        ses.ojb.Add(p1)

                                        Dim p2 As New Pregunta
                                        p2.id = 132
                                        p2.respuesta = datgri.Rows(i).Cells(1).Value & "-" & datgri.Rows(i).Cells(3).Value
                                        p2.respuestaOLP = ""
                                        p2.idOLP = ""
                                        ses.ojb.Add(p2)
                                    Next
                                End If
                            End If
                        Next s
                    End If
                Next j
                strJson.Add(ses)
            End If
        Next x
        objJson = JsonConvert.SerializeObject(strJson)
        Console.Write(objJson)
        setEvaluacion(Me.formaParent)
    End Sub
    Function controlesAnidados(ByVal nombre As String, ByVal id As String, ByVal forma As System.Windows.Forms.Panel, ByVal pos As Integer, ByVal tipo As String, ByVal flag As Integer, ByVal idOLP As String) As System.Windows.Forms.Panel
        Dim dstRecord As New DataSet
        Dim ancho As Integer, localiza As Integer
        Select Case tipo
            Case "1" 'texto 
                If (flag = 1) Then
                    Me.lab = New System.Windows.Forms.Label
                    Me.lab.Text = nombre
                    Me.lab.Location = New System.Drawing.Point(pos + 10, 0)
                    Me.lab.Size = New System.Drawing.Size(100, 20)
                    Me.lab.TabIndex = 0
                    forma.Controls.Add(Me.lab)
                    pos += Me.rad.Size.Width
                End If
                IIf(idOLP <> "", "", idOLP = id)
                Me.tex = New System.Windows.Forms.TextBox
                ancho = Me.lab.Location.X + Me.lab.Size.Width
                Me.tex.Name = id & "-" & idOLP
                Me.tex.Location = New System.Drawing.Point(ancho, 0)
                Me.tex.Size = New System.Drawing.Size(300, 20)
                Me.tex.Visible = True
                forma.Controls.Add(Me.tex)
            Case "2" 'radio
                dstRecord.Tables.Add("vistapreguntarespuesta")
                mdlCRUD.loadRecord(dstRecord, "vistapreguntarespuesta", "vistapreguntarespuesta", "pregunta_id = '" & id & "'", "")
                If (flag = 1) Then
                    Me.lab = New System.Windows.Forms.Label
                    Me.lab.Text = nombre
                    Me.lab.Location = New System.Drawing.Point(pos, 0)
                    If (nombre.ToString.Length > 25) Then
                        'Me.lab.Size = New System.Drawing.Size(nombre.ToString.Length * 5, 20)
                        Me.lab.Size = New System.Drawing.Size(200, 0)
                    Else
                        'Me.lab.Size = New System.Drawing.Size(nombre.ToString.Length * 6, 20)
                        Me.lab.Size = New System.Drawing.Size(200, 0)
                    End If
                    'Me.lab.Size = New System.Drawing.Size(nombre.ToString.Length * 5, 0)
                    Me.lab.TabIndex = 0
                    forma.Controls.Add(Me.lab)
                    pos += Me.rad.Size.Width
                End If
                '--------radio 
                If (dstRecord.Tables("vistapreguntarespuesta").Rows.Count > 0) Then
                    For i = 0 To dstRecord.Tables("vistapreguntarespuesta").Rows.Count - 1
                        arrRow = dstRecord.Tables("vistapreguntarespuesta").Rows(i).ItemArray.ToArray
                        Me.rad = New System.Windows.Forms.RadioButton
                        'ancho = ((pos) + (i * 5))
                        If (i = 0) Then
                            ancho = (Me.lab.Size.Width + 2 + (i * 20))
                        Else
                            ancho = pos
                        End If
                        Me.rad.Checked = False
                        Me.rad.Text = arrRow(2)
                        Me.rad.Name = arrRow(4) & "-" & id & "-" & arrRow(5) & "-" & arrRow(6)
                        Me.rad.Location = New System.Drawing.Point(ancho, 0)
                        If (arrRow(2).ToString.Length > 8) Then
                            'Me.rad.Size = New System.Drawing.Size(arrRow(2).ToString.Length * 7, 20)
                            Me.rad.Size = New System.Drawing.Size(50, 20)
                        Else
                            'Me.rad.Size = New System.Drawing.Size(arrRow(2).ToString.Length * 20, 20)
                            Me.rad.Size = New System.Drawing.Size(50, 20)
                        End If
                        'Me.rad.Size = New System.Drawing.Size(100, 20)
                        Me.rad.Visible = True
                        forma.Controls.Add(Me.rad)
                        pos = Me.rad.Location.X + Me.rad.Size.Width
                    Next i
                End If
                Me.utiladd = pos
            Case "3" 'selecion

            Case "4" 'cheke

        End Select
        Return forma
    End Function
    Function setEvaluacion(ByVal forma As Form) As Integer
        Dim frmResultado As New frmResultado
        Dim Ctl As Control
        Dim checklistbox As CheckedListBox
        Dim combobox As ComboBox
        For x = Me.formaParent.Controls.Count - 1 To 0 Step -1
            Ctl = Me.formaParent.Controls.Item(x)
            If TypeOf (Ctl) Is GroupBox Then
                Dim Control As GroupBox = Ctl
                For j = Control.Controls.Count - 1 To 0 Step -1
                    Ctl = Control.Controls.Item(j)
                    If TypeOf (Ctl) Is CheckedListBox Then
                        checklistbox = Ctl
                    End If
                Next j
            End If
        Next x

        Dim arrCampos() As String = {"resultado_id", "resultado_fecha", "resultado_hora", "resultado_texto", "estadosaprovacionexamenes_id", "certificaciones_id", "prueba_id", "usuario_id"}
        Dim strId As Integer = mdlCRUD.getConsecutivo("resultado", "resultado_id", 1)
        Dim arrValor() As String = {strId, Date.Now, "", Me.objJson.ToString, frmEvaluaciones.cblResultado.SelectedValue.ToString, mdlEvaluaciones.idcertificado, mdlEvaluaciones.idprueba, clssIdentidad.sID}
        mdlCRUD.insRecord("resultado", arrCampos, arrValor)

        For Each chkList In checklistbox.CheckedItems
            Dim arrCamposRestriccion() As String = {"resultado_id", "restriccion_id"}
            Dim arrValorRestriccion() As String = {Trim(strId), Trim(chkList.Item("restriccion_id").ToString)}
            mdlCRUD.insRecord("resultadorestricciones", arrCamposRestriccion, arrValorRestriccion)
        Next

        frmResultado.save_pdf(strId)
        forma.Close()
        Return 1
    End Function
    Function getEvaluacion(ByVal json As String) As sessionR()
        Dim ojbdes As New JArray
        Dim ultimo As Integer = 0
        ojbdes = JsonConvert.DeserializeObject(json)
        Dim Rootobject() As sessionR = (
                                         From j In ojbdes
                                         Select New sessionR() With {.id = j("id"),
                                                                    .ojb = (
                                                                            From i In j("ojb")
                                                                            Select New Pregunta() With {
                                                                                    .id = i("id"),
                                                                                    .respuesta = i("respuesta"),
                                                                                    .respuestaOLP = i("respuestaOLP"),
                                                                                    .idOLP = i("idOLP")
                                                                                }
                                                                        ).ToArray()
                                                                   }
                                       ).ToArray()

        Return Rootobject
    End Function
    Public Sub graficaFonoaudologia(ByVal forma As System.Windows.Forms.GroupBox, ByVal ruta As String, ByVal aspirante As String)
        Dim ancho As Integer, localiza As Integer, cont As Integer = 0, tipo As Integer = 0
        Dim contadorX As Integer = 10, contadorY As Integer = 0
        Dim titleY1 As String() = {"250", "500", "1000", "2000", "3000", "4000", "6000", "8000"}
        Dim titleY2 As String() = {"250", "500", "1000", "2000", "4000", "8000"}
        localiza = (forma.Width / 2) + 10

        Me.pan = New System.Windows.Forms.Panel
        Me.pan.Name = "detallegrafico"
        Me.pan.Location = New System.Drawing.Point(10, 20)
        Me.pan.Size = New System.Drawing.Size(((forma.Width / 2) - 10), 450)
        Me.pan.BorderStyle = BorderStyle.FixedSingle

        Me.dgrigv = New System.Windows.Forms.DataGridView
        'Me.dgrigv.Name = "dgvDetalle"
        Me.dgrigv.Location = New System.Drawing.Point(10, 10)
        Me.dgrigv.Size = New System.Drawing.Size(((forma.Width / 2) - 30), 350)
        Me.dgrigv.Columns.Add("EXAMEN", "EXAMEN")
        Me.dgrigv.Columns.Add("PARAM (Hz)", "PARAM (Hz)")
        Me.dgrigv.Columns.Add("Oido Der. (dB)", "Oido Der. (dB)")
        Me.dgrigv.Columns.Add("Oido Izq. (dB)", "Oido Izq. (dB)")

        Me.bot = New System.Windows.Forms.Button
        Me.bot.Location = New System.Drawing.Point(100, (Me.dgrigv.Size.Height + 30))
        Me.bot.Size = New System.Drawing.Size(300, 23)
        Me.bot.Text = "Cargar Datos"
        AddHandler bot.Click, AddressOf boton_Click

        Me.pan.Controls.Add(Me.dgrigv)
        Me.pan.Controls.Add(Me.bot)
        forma.Controls.Add(pan)

        Me.pang = New System.Windows.Forms.Panel
        'Me.pang.Name = "consolgrafico"
        Me.pang.Location = New System.Drawing.Point(localiza, 20)
        Me.pang.Size = New System.Drawing.Size(((forma.Width / 2) - 20), 450)
        Me.pang.BorderStyle = BorderStyle.FixedSingle

        Dim shapecon As New ShapeContainer
        Me.ruta = ruta
        tipo = tipoarchivo(ruta)
        Me.tipoEquipo = tipo
        If (tipo = 1) Then
            ' EJE X
            For i = 110 To (Me.pang.Size.Width + 20) Step 55
                Me.lab = New System.Windows.Forms.Label
                If (cont < 6) Then
                    Me.lab.Text = titleY2(cont)
                End If
                Me.lab.Name = i
                Me.lab.Location = New System.Drawing.Point(i - 10, 0)
                Me.lab.Size = New System.Drawing.Size(40, 20)
                Me.lab.TabIndex = 0
                Me.pang.Controls.Add(lab)

                Dim linea As New LineShape
                shapecon.CreateControl()
                shapecon.Parent = Me.pang
                linea.Parent = shapecon
                linea.StartPoint = New System.Drawing.Point(i, 0)
                linea.EndPoint = New System.Drawing.Point(i, (Me.pang.Size.Height - 30))
                Me.pang.Controls.Add(shapecon)
                cont = cont + 1
            Next i
        End If
        If (tipo = 2) Then
            ' EJE X
            For i = 90 To (Me.pang.Size.Width + 20) Step 45
                Me.lab = New System.Windows.Forms.Label
                If (cont < 8) Then
                    Me.lab.Text = titleY1(cont)
                End If
                Me.lab.Name = i
                Me.lab.Location = New System.Drawing.Point(i - 10, 0)
                Me.lab.Size = New System.Drawing.Size(40, 20)
                Me.lab.TabIndex = 0
                Me.pang.Controls.Add(lab)

                Dim linea As New LineShape
                shapecon.CreateControl()
                shapecon.Parent = Me.pang
                linea.Parent = shapecon
                linea.StartPoint = New System.Drawing.Point(i, 0)
                linea.EndPoint = New System.Drawing.Point(i, (Me.pang.Size.Height - 30))
                Me.pang.Controls.Add(shapecon)
                cont = cont + 1
            Next i
        End If
        ' EJE Y
        For i = 30 To Me.pan.Height - 30 Step 30
            Me.lab = New System.Windows.Forms.Label
            Me.lab.Text = contadorY
            Me.lab.Name = i
            Me.lab.Location = New System.Drawing.Point(20, i - 10)
            Me.lab.Size = New System.Drawing.Size(30, 20)
            Me.lab.TabIndex = 0
            Me.pang.Controls.Add(lab)

            Dim linea As New LineShape
            shapecon.CreateControl()
            shapecon.Parent = Me.pang
            linea.Parent = shapecon
            linea.StartPoint = New System.Drawing.Point((Me.lab.Size.Width + 20), i)
            linea.EndPoint = New System.Drawing.Point((Me.pang.Size.Width - 30), i)
            Me.pang.Controls.Add(shapecon)
            contadorY = contadorY + 10
        Next i
        forma.Controls.Add(pang)
    End Sub
    Protected Sub boton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim arrText As ArrayList
        Dim arrMDB As ArrayList
        Dim arrIdResult1 As Array
        Dim arrIdResult2 As Array
        Dim arrEvAudio(7) As String
        Dim cadenaAudio As String = ""
        Dim titleY1 As String() = {"250", "500", "1000", "2000", "3000", "4000", "6000", "8000"}
        Dim xpos As Integer = 0
        Dim ypos As Integer = 0
        Dim yanpos As Integer = 0
        Dim con As Integer = 0
        Dim con2 As Integer = 0
        If (tipoEquipo = 2) Then
            arrMDB = LeerMDB(Me.ruta)
            Dim shapecon As New ShapeContainer
            Try
                If (arrMDB.Count > 0) Then
                    arrIdResult1 = arrMDB(0)
                    arrIdResult2 = arrMDB(1)
                    Me.dgrigv.RowCount = 8
                    con = 2
                    For j = 0 To Me.dgrigv.RowCount - 1
                        If (con = 5) Then
                            con = con + 1
                        End If
                        Me.dgrigv.Rows(j).Cells(0).Value = "Agudeza auditiva"
                        Me.dgrigv.Rows(j).Cells(1).Value = titleY1(con2)
                        Me.dgrigv.Rows(j).Cells(2).Value = arrIdResult1(con)
                        Me.dgrigv.Rows(j).Cells(3).Value = arrIdResult2(con)
                        arrEvAudio(j) = arrIdResult1(con) & "," & arrIdResult2(con) & "," & titleY1(con2)
                        con = con + 1
                        con2 = con2 + 1
                    Next j
                End If
            Catch ex As Exception
                Exit Sub
            End Try
            cadenaAudio = ""
            con = 0
            ' OIDO IZQUIERDO 
            Dim xanpos As Integer = 90
            For Each ListA In arrEvAudio
                Dim linea As New LineShape
                Dim lin1, lin2, lin3, lin4 As New LineShape
                Dim arrvar As Array
                arrvar = Split(ListA, ",")
                If (arrvar.Length > 1) Then
                    If (arrvar(2) = "250") Then
                        xpos = 90
                    End If
                    If (arrvar(2) = "500") Then
                        xpos = 135
                    End If
                    If (arrvar(2) = "1000") Then
                        xpos = 180
                    End If
                    If (arrvar(2) = "2000") Then
                        xpos = 225
                    End If
                    If (arrvar(2) = "3000") Then
                        xpos = 270
                    End If
                    If (arrvar(2) = "4000") Then
                        xpos = 315
                    End If
                    If (arrvar(2) = "6000") Then
                        xpos = 360
                    End If
                    If (arrvar(2) = "8000") Then
                        xpos = 405
                    End If
                    If (con = 0) Then
                        yanpos = ((arrvar(1) + 10) * 3)
                        ypos = ((arrvar(1) + 10) * 3)
                        Console.WriteLine(arrvar(0) & "=" & ypos)
                    Else
                        ypos = ((arrvar(1) + 10) * 3)
                    End If
                    shapecon.CreateControl()
                    shapecon.Parent = Me.pang
                    linea.Parent = shapecon
                    lin1.Parent = shapecon
                    lin2.Parent = shapecon
                    linea.BorderColor = Color.Blue
                    linea.BorderWidth = 4
                    lin1.BorderColor = Color.Blue
                    lin1.BorderWidth = 4
                    lin2.BorderColor = Color.Blue
                    lin2.BorderWidth = 4
                    linea.EndPoint = New System.Drawing.Point(xpos, ypos)
                    linea.StartPoint = New System.Drawing.Point(xanpos, yanpos)

                    lin1.EndPoint = New System.Drawing.Point(xpos + 7, ypos + 7)
                    lin1.StartPoint = New System.Drawing.Point(xpos - 7, ypos - 7)
                    lin2.EndPoint = New System.Drawing.Point(xpos - 7, ypos + 7)
                    lin2.StartPoint = New System.Drawing.Point(xpos + 7, ypos - 7)
                    xanpos = xpos
                    yanpos = ypos
                End If
                con = con + 1
            Next
            con = 0
            xanpos = 100
            yanpos = 0
            For Each ListA In arrEvAudio
                Dim linea As New LineShape
                Dim circule As New OvalShape
                Dim arrvar As Array
                arrvar = Split(ListA, ",")
                If (arrvar.Length > 1) Then
                    If (arrvar(2) = "250") Then
                        xpos = 90
                    End If
                    If (arrvar(2) = "500") Then
                        xpos = 135
                    End If
                    If (arrvar(2) = "1000") Then
                        xpos = 180
                    End If
                    If (arrvar(2) = "2000") Then
                        xpos = 225
                    End If
                    If (arrvar(2) = "3000") Then
                        xpos = 270
                    End If
                    If (arrvar(2) = "4000") Then
                        xpos = 315
                    End If
                    If (arrvar(2) = "6000") Then
                        xpos = 360
                    End If
                    If (arrvar(2) = "8000") Then
                        xpos = 405
                    End If
                    If (con = 0) Then
                        yanpos = ((arrvar(0) + 10) * 3)
                        ypos = ((arrvar(0) + 10) * 3)
                    Else
                        ypos = ((arrvar(0) + 10) * 3)
                    End If
                    shapecon.CreateControl()
                    shapecon.Parent = Me.pang
                    linea.Parent = shapecon
                    circule.Parent = shapecon
                    linea.BorderColor = Color.Red
                    linea.BorderWidth = 4
                    linea.EndPoint = New System.Drawing.Point(xpos, ypos)
                    linea.StartPoint = New System.Drawing.Point(xanpos, yanpos)
                    circule.Size = New System.Drawing.Size(10, 10)
                    circule.FillColor = Color.Red
                    circule.FillStyle = FillStyle.Solid
                    circule.Location = New System.Drawing.Point(xpos - 2, (ypos - 5))
                    xanpos = xpos
                    yanpos = ypos
                End If
                con = con + 1
            Next
        Else
            If (tipoEquipo = 1) Then
                ' OIDO IZQUIERDO 
                arrText = LeerTxt(Me.ruta)
                Dim shapecon As New ShapeContainer
                'For Each sLine In arrText
                'arrIdResult1 = Split(sLine, ",,")
                arrIdResult1 = Split(arrText(0), ",,")
                If (arrIdResult1(0) <> "") Then
                    arrIdResult2 = Split(arrIdResult1(1), ",")
                    Me.dgrigv.RowCount = (arrIdResult2.Length / 3)
                    For j = 0 To Me.dgrigv.RowCount - 2
                        Me.dgrigv.Rows(j).Cells(0).Value = "Agudeza auditiva"
                        For s = 3 To 1 Step -1
                            Me.dgrigv.Rows(j).Cells(s).Value = arrIdResult2(con)
                            If (s = 3) Then
                                cadenaAudio &= arrIdResult2(con)
                            Else
                                cadenaAudio &= "," & arrIdResult2(con)
                            End If
                            con = con + 1
                        Next s
                        arrEvAudio(j) = cadenaAudio
                        cadenaAudio = ""
                    Next j
                End If
                con = 0
                Dim xanpos As Integer = 110
                For Each ListA In arrEvAudio
                    Dim linea As New LineShape
                    Dim lin1, lin2, lin3, lin4 As New LineShape
                    Dim arrvar As Array
                    arrvar = Split(ListA, ",")
                    If (arrvar.Length > 1) Then
                        If (arrvar(2) = "250") Then
                            xpos = 110
                        End If
                        If (arrvar(2) = "500") Then
                            xpos = 165
                        End If
                        If (arrvar(2) = "1000") Then
                            xpos = 220
                        End If
                        If (arrvar(2) = "2000") Then
                            xpos = 275
                        End If
                        If (arrvar(2) = "4000") Then
                            xpos = 330
                        End If
                        If (arrvar(2) = "8000") Then
                            xpos = 385
                        End If
                        If (con = 0) Then
                            yanpos = ((arrvar(1) + 10) * 3)
                            ypos = ((arrvar(1) + 10) * 3)
                            Console.WriteLine(arrvar(0) & "=" & ypos)
                        Else
                            ypos = ((arrvar(1) + 10) * 3)
                        End If
                        shapecon.CreateControl()
                        shapecon.Parent = Me.pang
                        linea.Parent = shapecon
                        lin1.Parent = shapecon
                        lin2.Parent = shapecon
                        lin3.Parent = shapecon
                        lin4.Parent = shapecon
                        linea.BorderColor = Color.Blue
                        linea.BorderWidth = 4
                        lin1.BorderColor = Color.Blue
                        lin1.BorderWidth = 4
                        lin2.BorderColor = Color.Blue
                        lin2.BorderWidth = 4

                        linea.EndPoint = New System.Drawing.Point(xpos, ypos)
                        linea.StartPoint = New System.Drawing.Point(xanpos, yanpos)

                        lin1.EndPoint = New System.Drawing.Point(xpos + 7, ypos + 7)
                        lin1.StartPoint = New System.Drawing.Point(xpos - 7, ypos - 7)
                        lin2.EndPoint = New System.Drawing.Point(xpos - 7, ypos + 7)
                        lin2.StartPoint = New System.Drawing.Point(xpos + 7, ypos - 7)

                        xanpos = xpos
                        yanpos = ypos
                    End If
                    con = con + 1
                Next
                con = 0
                xanpos = 100
                yanpos = 0
                For Each ListA In arrEvAudio
                    Dim linea As New LineShape
                    Dim circule As New OvalShape
                    Dim arrvar As Array
                    arrvar = Split(ListA, ",")
                    If (arrvar.Length > 1) Then
                        If (arrvar(2) = "250") Then
                            xpos = 110
                        End If
                        If (arrvar(2) = "500") Then
                            xpos = 165
                        End If
                        If (arrvar(2) = "1000") Then
                            xpos = 220
                        End If
                        If (arrvar(2) = "2000") Then
                            xpos = 275
                        End If
                        If (arrvar(2) = "4000") Then
                            xpos = 330
                        End If
                        If (arrvar(2) = "8000") Then
                            xpos = 385
                        End If
                        If (con = 0) Then
                            yanpos = ((arrvar(0) + 10) * 3)
                            ypos = ((arrvar(0) + 10) * 3)
                        Else
                            ypos = ((arrvar(0) + 10) * 3)
                        End If
                        shapecon.CreateControl()
                        shapecon.Parent = Me.pang
                        linea.Parent = shapecon
                        circule.Parent = shapecon
                        linea.BorderColor = Color.Red
                        linea.BorderWidth = 4
                        linea.EndPoint = New System.Drawing.Point(xpos, ypos)
                        linea.StartPoint = New System.Drawing.Point(xanpos, yanpos)
                        circule.Size = New System.Drawing.Size(10, 10)
                        circule.FillColor = Color.Red
                        circule.FillStyle = FillStyle.Solid
                        circule.Location = New System.Drawing.Point(xpos - 2, (ypos - 5))
                        xanpos = xpos
                        yanpos = ypos
                    End If
                    con = con + 1
                Next
            End If
        End If
        'Next
    End Sub
    Public Function datosPsicologia(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal idOLP As String, ByVal ultimo As Integer) As Integer
        Dim ancho As Integer, con As Integer, posi As Integer = 20, ancho2 As Integer
        Dim pregun1() As String = {"TRM (<=74)", "TMR (<=136)", "MDA (<=44)", "NE (<=155)"}
        Dim id1() As String = {"113", "115", "117", "118"}
        Dim pregun2() As String = {"NE (<=5)", "NE (<=7)", "", "TE (<=6271)"}
        Dim id2() As String = {"114", "116", "", "119"}

        Me.bot = New System.Windows.Forms.Button
        Me.bot.Location = New System.Drawing.Point(300, 10)
        Me.bot.Size = New System.Drawing.Size(300, 23)
        Me.bot.Text = "Cargar Datos"
        'AddHandler bot.Click, AddressOf boton_Click
        forma.Controls.Add(Me.bot)
        For e = 0 To 3
            con = con + 1
            Me.pan = New System.Windows.Forms.Panel
            Me.pan.Location = New System.Drawing.Point(posi, 40)
            Me.pan.Size = New System.Drawing.Size(210, 40)
            Me.pan.BorderStyle = BorderStyle.FixedSingle

            Me.lab = New System.Windows.Forms.Label
            Me.lab.Location = New System.Drawing.Point(0, 0)
            Me.lab.Text = con
            Me.lab.Size = New System.Drawing.Size(20, 15)
            Me.lab.TabIndex = 0

            Me.pan.Controls.Add(Me.lab)

            Me.lab = New System.Windows.Forms.Label
            Me.lab.Location = New System.Drawing.Point(0, 18)
            Me.lab.Text = pregun1(e)
            'Me.lab.Name = id1(e)
            Me.lab.Size = New System.Drawing.Size(70, 20)
            Me.lab.TabIndex = 0

            Me.tex = New System.Windows.Forms.TextBox
            'ancho = nombre.ToString.Length * 10
            ancho = Me.lab.Size.Width + 5
            Me.tex.Name = id1(e) & "-" & id1(e)
            Me.tex.Location = New System.Drawing.Point(ancho, 15)
            Me.tex.Size = New System.Drawing.Size(30, 20)
            Me.tex.Visible = True

            Me.pan.Controls.Add(Me.lab)
            Me.pan.Controls.Add(Me.tex)

            ancho2 = 105
            If (e <> 2) Then
                Me.lab = New System.Windows.Forms.Label
                Me.lab.Text = pregun2(e)
                'Me.lab.Name = id
                Me.lab.Location = New System.Drawing.Point(ancho2, 18)
                Me.lab.Size = New System.Drawing.Size(70, 20)
                Me.lab.TabIndex = 0


                Me.tex = New System.Windows.Forms.TextBox
                'ancho = nombre.ToString.Length * 10
                ancho = Me.lab.Size.Width + ancho2
                Me.tex.Name = id2(e) & "-" & id2(e)
                Me.tex.Location = New System.Drawing.Point(ancho, 15)
                Me.tex.Size = New System.Drawing.Size(30, 20)
                Me.tex.Visible = True

                Me.pan.Controls.Add(Me.lab)
                Me.pan.Controls.Add(Me.tex)
            End If
            forma.Controls.Add(Me.pan)
            posi = Me.pan.Location.X + Me.pan.Width + 2

        Next e
        Return 20
    End Function
    Public Function datospruebaPsicologia(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.GroupBox, ByVal pos As Integer, ByVal idOLP As String, ByVal ultimo As Integer) As Integer
        Dim ancho As Integer, con As Integer, posi As Integer = 20, ancho2 As Integer


        Me.pan = New System.Windows.Forms.Panel
        Me.pan.Location = New System.Drawing.Point(posi, 20)
        Me.pan.Size = New System.Drawing.Size((forma.Width / 2), 40)
        Me.pan.BorderStyle = BorderStyle.FixedSingle

        Me.bot = New System.Windows.Forms.Button
        Me.bot.Location = New System.Drawing.Point(20, 10)
        Me.bot.Size = New System.Drawing.Size(100, 23)
        Me.bot.Text = "Prueba Psico"
        AddHandler bot.Click, AddressOf botonPsico_Click
        Me.pan.Controls.Add(Me.bot)
        ancho = Me.bot.Size.Width + Me.bot.Location.X

        Me.lab = New System.Windows.Forms.Label
        Me.lab.Location = New System.Drawing.Point(ancho, 15)
        Me.lab.Text = "Personalidad"
        Me.lab.Size = New System.Drawing.Size(100, 15)
        Me.lab.TabIndex = 0

        Me.pan.Controls.Add(Me.lab)

        ancho = Me.lab.Size.Width + Me.lab.Location.X

        Me.tex = New System.Windows.Forms.TextBox
        Me.tex.Name = ""
        Me.tex.Location = New System.Drawing.Point(ancho, 10)
        Me.tex.Size = New System.Drawing.Size(70, 20)
        Me.tex.Visible = True

        Me.pan.Controls.Add(Me.tex)

        ancho = Me.tex.Size.Width + Me.tex.Location.X
        Me.lab = New System.Windows.Forms.Label
        Me.lab.Location = New System.Drawing.Point(ancho, 15)
        Me.lab.Text = "CI"
        Me.lab.Size = New System.Drawing.Size(20, 15)
        Me.lab.TabIndex = 0

        Me.pan.Controls.Add(Me.lab)

        Me.tex = New System.Windows.Forms.TextBox
        ancho = Me.lab.Size.Width + Me.lab.Location.X
        Me.tex.Name = ""
        Me.tex.Location = New System.Drawing.Point(ancho, 10)
        Me.tex.Size = New System.Drawing.Size(40, 20)
        Me.tex.Visible = True

        Me.pan.Controls.Add(Me.tex)
        forma.Controls.Add(Me.pan)

        Me.pan = New System.Windows.Forms.Panel
        Me.pan.Location = New System.Drawing.Point((forma.Width / 2) + 10, 20)
        Me.pan.Size = New System.Drawing.Size((forma.Width / 2) - 50, 40)
        Me.pan.BorderStyle = BorderStyle.FixedSingle

        Me.lab = New System.Windows.Forms.Label
        Me.lab.Location = New System.Drawing.Point(10, 15)
        Me.lab.Text = "Tiempo de Reaccional frenado <=60"
        'Me.lab.Name = id1(e)
        Me.lab.Size = New System.Drawing.Size(200, 20)
        Me.lab.TabIndex = 0

        Me.pan.Controls.Add(Me.lab)

        Me.tex = New System.Windows.Forms.TextBox
        ancho = Me.lab.Size.Width + Me.lab.Location.X
        Me.tex.Name = ""
        Me.tex.Location = New System.Drawing.Point(ancho, 10)
        Me.tex.Size = New System.Drawing.Size(30, 20)
        Me.tex.Visible = True

        Me.lab = New System.Windows.Forms.Label
        ancho = Me.tex.Size.Width + Me.tex.Location.X
        Me.lab.Location = New System.Drawing.Point(ancho, 15)
        Me.lab.Text = "CS"
        'Me.lab.Name = id1(e)
        Me.lab.Size = New System.Drawing.Size(50, 20)
        Me.lab.TabIndex = 0

        Me.pan.Controls.Add(Me.lab)
        Me.pan.Controls.Add(Me.tex)
        forma.Controls.Add(Me.pan)
        Return 0
    End Function
    Protected Sub botonPsico_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        LeerMDB("C:\Users\jortiz\Documents\poryecto src\PRUEBA 1  PACIENTE.mdb")
    End Sub
    Public Function estados(ByVal nombre As String, ByVal columna As Integer, ByVal id As String, ByVal forma As System.Windows.Forms.Form, ByVal ultimo As Integer, ByVal idOLP As String) As Integer
        Dim dstRecord As New DataSet
        Dim ancho As Integer, localiza As Integer
        dstRecord.Tables.Add("estadosaprovacionexamenes")
        mdlCRUD.loadRecord(dstRecord, "estadosaprovacionexamenes", "estadosaprovacionexamenes", "", "")
        Dim grb As New GroupBox
        grb.Location = New System.Drawing.Point(20, ultimo + 10)
        grb.Size = New System.Drawing.Size(forma.Width - 100, 50)
        grb.Text = "RESULTADOS"

        'localiza = 10

        'Me.pan = New System.Windows.Forms.Panel
        'Me.pan.Location = New System.Drawing.Point(localiza, 20)
        'Me.pan.Size = New System.Drawing.Size((forma.Width - 100), 20)

        Me.lab = New System.Windows.Forms.Label
        Me.lab.Text = nombre
        Me.lab.Name = id
        Me.lab.Size = New System.Drawing.Size(nombre.Length * 10, 20)
        Me.lab.TabIndex = 0

        'Me.pan.Controls.Add(lab)
        grb.Controls.Add(lab)
        '--------seleccion

        Me.cob = New System.Windows.Forms.ComboBox
        ancho = nombre.ToString.Length * 10
        Me.cob.Name = "Result"
        Me.cob.DataSource = dstRecord.Tables("estadosaprovacionexamenes")
        Me.cob.DisplayMember = dstRecord.Tables("estadosaprovacionexamenes").Columns(1).ToString
        Me.cob.ValueMember = dstRecord.Tables("estadosaprovacionexamenes").Columns(0).ToString
        Me.cob.Location = New System.Drawing.Point(ancho, 0)
        Me.cob.Size = New System.Drawing.Size(200, 20)
        Me.cob.Visible = True
        'Me.pan.Controls.Add(Me.cob)
        grb.Controls.Add(Me.cob)
        forma.Controls.Add(grb)
        Return grb.Height
    End Function
    Function pintarGraficacertifi(ByVal pang As System.Windows.Forms.Panel, ByVal arraresul As String) As Integer
        Dim arrText As ArrayList
        Dim arrMDB As ArrayList
        Dim arrIdResult1 As Array
        Dim arrIdResult2 As Array
        Dim arrEvAudio(7) As String
        Dim cadenaAudio As String = ""
        Dim titleY1 As String() = {"250", "500", "1000", "2000", "3000", "4000", "6000", "8000"}
        Dim xpos As Integer = 0
        Dim ypos As Integer = 0
        Dim yanpos As Integer = 0
        Dim con As Integer = 0
        Dim con2 As Integer = 0
        tipoEquipo = 1
        If (tipoEquipo = 1) Then

            Dim shapecon As New ShapeContainer
            cadenaAudio = ""
            con = 0
            ' OIDO IZQUIERDO 
            Dim xanpos As Integer = 63
            'For Each ListA In arrEvAudio
            Dim linea As New LineShape
            Dim lin1, lin2 As New LineShape
            Dim arrvar As Array
            arrvar = Split(arraresul, "-")
            If (arrvar.Length > 1) Then
                Select Case (arrvar(0))
                    Case "250" : xpos = 63
                    Case "500" : xpos = 90
                    Case "1000" : xpos = 117
                    Case "2000" : xpos = 144
                    Case "4000" : xpos = 171
                    Case "8000" : xpos = 198
                End Select
                'If (con = 0) Then
                '    yanpos = ((arrvar(1) + 10) * 3)
                '    ypos = ((arrvar(1) + 10) * 3)
                '    Console.WriteLine(arrvar(0) & "=" & ypos)
                'Else
                '    ypos = ((arrvar(1) + 10) * 3)
                'End If
                ypos = Val(arrvar(1)) * 3
                shapecon.CreateControl()
                shapecon.Parent = pang
                linea.Parent = shapecon
                lin1.Parent = shapecon
                lin2.Parent = shapecon
                linea.BorderColor = Color.Blue
                linea.BorderWidth = 4
                lin1.BorderColor = Color.Blue
                lin1.BorderWidth = 4
                lin2.BorderColor = Color.Blue
                lin2.BorderWidth = 4
                linea.EndPoint = New System.Drawing.Point(63, 30)
                linea.StartPoint = New System.Drawing.Point(90, 90)
                'linea.EndPoint = New System.Drawing.Point(xpos, ypos)
                'linea.StartPoint = New System.Drawing.Point(xanposc, yanposc)

                lin1.EndPoint = New System.Drawing.Point(xpos + 7, ypos + 7)
                lin1.StartPoint = New System.Drawing.Point(xpos - 7, ypos - 7)
                lin2.EndPoint = New System.Drawing.Point(xpos - 7, ypos + 7)
                lin2.StartPoint = New System.Drawing.Point(xpos + 7, ypos - 7)
                xanposc = xpos
                yanposc = ypos
            End If
            con = con + 1
            ' Next
            con = 0
            xanpos = 100
            yanpos = 0
            'For Each ListA In arrEvAudio
            '    Dim linea As New LineShape
            '    Dim circule As New OvalShape
            '    Dim arrvar As Array
            '    arrvar = Split(ListA, ",")
            '    If (arrvar.Length > 1) Then
            '        If (arrvar(2) = "250") Then
            '            xpos = 90
            '        End If
            '        If (arrvar(2) = "500") Then
            '            xpos = 135
            '        End If
            '        If (arrvar(2) = "1000") Then
            '            xpos = 180
            '        End If
            '        If (arrvar(2) = "2000") Then
            '            xpos = 225
            '        End If
            '        If (arrvar(2) = "3000") Then
            '            xpos = 270
            '        End If
            '        If (arrvar(2) = "4000") Then
            '            xpos = 315
            '        End If
            '        If (arrvar(2) = "6000") Then
            '            xpos = 360
            '        End If
            '        If (arrvar(2) = "8000") Then
            '            xpos = 405
            '        End If
            '        If (con = 0) Then
            '            yanpos = ((arrvar(0) + 10) * 3)
            '            ypos = ((arrvar(0) + 10) * 3)
            '        Else
            '            ypos = ((arrvar(0) + 10) * 3)
            '        End If
            '        shapecon.CreateControl()
            '        shapecon.Parent = Me.pang
            '        linea.Parent = shapecon
            '        circule.Parent = shapecon
            '        linea.BorderColor = Color.Red
            '        linea.BorderWidth = 4
            '        linea.EndPoint = New System.Drawing.Point(xpos, ypos)
            '        linea.StartPoint = New System.Drawing.Point(xanpos, yanpos)
            '        circule.Size = New System.Drawing.Size(10, 10)
            '        circule.FillColor = Color.Red
            '        circule.FillStyle = FillStyle.Solid
            '        circule.Location = New System.Drawing.Point(xpos - 2, (ypos - 5))
            '        xanpos = xpos
            '        yanpos = ypos
            '    End If
            '    con = con + 1
            'Next
        Else

        End If
        'Next
        Return 0
    End Function
    Public Sub graficaFonocertificador(ByVal forma As System.Windows.Forms.GroupBox, ByVal ruta As String, ByVal aspirante As String)
        Dim ancho As Integer, localiza As Integer, cont As Integer = 0, tipo As Integer = 0
        Dim contadorX As Integer = 10, contadorY As Integer = 0
        Dim titleY1 As String() = {"250", "500", "1000", "2000", "3000", "4000", "6000", "8000"}
        Dim titleY2 As String() = {"250", "500", "1000", "2000", "4000", "8000"}
        localiza = (forma.Width / 2)
        Dim pang As System.Windows.Forms.Panel
        Dim lab As System.Windows.Forms.Label
        
        'Me.pang.Name = "consolgrafico"
        pang = New System.Windows.Forms.Panel
        pang.Location = New System.Drawing.Point(localiza, 20)
        pang.Size = New System.Drawing.Size(((forma.Width / 2) - 20), 250)
        pang.BorderStyle = BorderStyle.FixedSingle

        Dim shapecon As New ShapeContainer
        'Me.ruta = ruta
        'tipo = tipoarchivo(ruta)
        tipo = 1
        Me.tipoEquipo = tipo
        If (tipo = 1) Then
            ' EJE X
            For i = 63 To (pang.Size.Width) Step 27
                lab = New System.Windows.Forms.Label
                If (cont < 6) Then
                    'lab.Text = titleY2(cont)
                    lab.Text = i
                End If
                lab.Name = i
                lab.Location = New System.Drawing.Point(i - 15, 0)
                lab.Font = New Font(lab.Name, 5, FontStyle.Regular)
                lab.Size = New System.Drawing.Size(20, 20)
                lab.TabIndex = 0
                pang.Controls.Add(lab)

                Dim linea As New LineShape
                shapecon.CreateControl()
                shapecon.Parent = pang
                linea.Parent = shapecon
                linea.StartPoint = New System.Drawing.Point(i, 0)
                linea.EndPoint = New System.Drawing.Point(i, (pang.Size.Height - 30))
                pang.Controls.Add(shapecon)
                cont = cont + 1
            Next i
        End If
        If (tipo = 2) Then
            ' EJE X
            For i = 90 To (pang.Size.Width + 20) Step 45
                lab = New System.Windows.Forms.Label
                If (cont < 8) Then
                    lab.Text = titleY1(cont)
                End If
                lab.Name = i
                lab.Location = New System.Drawing.Point(i - 10, 0)
                lab.Font = New Font(lab.Name, 6.5, FontStyle.Regular)
                lab.Size = New System.Drawing.Size(40, 20)
                lab.TabIndex = 0
                pang.Controls.Add(lab)

                Dim linea As New LineShape
                shapecon.CreateControl()
                shapecon.Parent = pang
                linea.Parent = shapecon
                linea.StartPoint = New System.Drawing.Point(i, 0)
                linea.EndPoint = New System.Drawing.Point(i, (pang.Size.Height - 30))
                pang.Controls.Add(shapecon)
                cont = cont + 1
            Next i
        End If
        ' EJE Y
        For i = 30 To pang.Height - 30 Step 15
            lab = New System.Windows.Forms.Label
            lab.Text = contadorY
            lab.Name = i
            lab.Font = New Font(lab.Name, 5, FontStyle.Regular)
            lab.Location = New System.Drawing.Point(20, i - 5)
            lab.Size = New System.Drawing.Size(30, 15)
            lab.TabIndex = 0
            pang.Controls.Add(lab)

            Dim linea As New LineShape
            shapecon.CreateControl()
            shapecon.Parent = pang
            linea.Parent = shapecon
            linea.StartPoint = New System.Drawing.Point((lab.Size.Width + 20), i)
            linea.EndPoint = New System.Drawing.Point((pang.Size.Width - 30), i)
            pang.Controls.Add(shapecon)
            contadorY = contadorY + 10
        Next i
        pintarGraficacertifi(pang, aspirante)
        forma.Controls.Add(pang)

    End Sub
End Class

